package com.sali.handler;

import com.sali.rule.*;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: sali
 * @date: 2024/7/16 21:14.
 * @version: 1.0
 */
public final class RuleHandle {

    /**
     * 保存以识别到的规则集合
     */
    private static final ConcurrentHashMap<String, Rule> RULES_MAP = new ConcurrentHashMap<>();

    static {
        RULES_MAP.put("ValueRule", ValueRule.getInstance());
        RULES_MAP.put("FieldNameToLowerCaseRule", FieldNameToLowerCaseRule.getInstance());
        RULES_MAP.put("InsertTimeRule", InsertTimeRule.getInstance());
        RULES_MAP.put("SnowflakeIdRule", SnowflakeIdRule.getInstance());
        RULES_MAP.put("IpTypeRule", IpTypeRule.getInstance());
        RULES_MAP.put("DataToTimestampRule", DataToTimestampRule.getInstance());
        RULES_MAP.put("TimestampRule", TimestampRule.getInstance());
        RULES_MAP.put("FileIdRule", FileIdRule.getInstance());
        RULES_MAP.put("NumIpToStrIp", NumIpToStrIp.getInstance());
        RULES_MAP.put("PasswordRule", PasswordRule.getInstance());
        RULES_MAP.put("DomainRule", DomainRule.getInstance());
    }

    /**
     * 解析规则
     *
     * @param ruleKey
     * @return
     */
    public static Rule handle(String ruleKey) {
        Rule rule;
        if (RULES_MAP.containsKey(ruleKey)) {
            rule = RULES_MAP.get(ruleKey);
        } else {
            rule = ValueRule.getInstance();
        }
        return rule;
    }

}
